package com.aaa.sbms.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @FileName:TrainVideoDao
 * @Description:培训视频管理
 * @Author :99728
 * @Date: 2020/6/22 16:20
 * @Version:1.0.0
 */

public interface TrainVideoDao {

    /**
     * 带参分页查询
     * @param map
     * @return
     */
    @Select("<script>select videoid,videoname,date_format(addtime,'%Y-%m-%d %h:%i:%s') addtime,intro,sshotpath,course.coursename\n" +
            "from trainvideo join course on course.courseid=trainvideo.courseid\n" +
            "<where> " +
            "<if test=\"coursename!=null\"> and course.coursename like concat('%',#{coursename},'%')</if>\n" +
            "</where> order by videoid " +
            "limit #{begin},#{pageSize}</script>")
    List<Map> getPage(Map map);

    /**
     * 带参数总条数查询
     * @param map
     * @return
     */
    @Select("<script>select count(*)" +
            "from trainvideo join course on course.courseid=trainvideo.courseid\n" +
            "<where> " +
            "<if test=\"coursename!=null\"> and course.coursename like concat('%',#{coursename},'%')</if>\n" +
            "</where></script>")
    int getPageCount(Map map);

    /**
     * 根据Id查寻信息
     * @param videoid
     * @return
     */
    @Select("select * from trainvideo where videoid = #{videoid}")
    Map onelist(int videoid);

    /**
     * 下拉 课程名称查询
     * @param map
     * @return
     */
    @Select("select courseid,coursename from course")
    List<Map> getCourseName(Map map);

    /**
     *
     * 添加
     * @param map
     * @return
     */
    @Insert("insert into trainvideo (videoname,intro,videopath,sshotpath,courseid,addtime)  " +
            "values(#{videoname},#{intro},#{videopath},#{sshotpath},#{courseid},date_format(now(),'%Y-%m-%d %h:%i')) ")
    int add(Map map);

    /**
     * 删除
     * @param videoid
     * @return
     */
    @Delete("delete from trainvideo where videoid=#{videoid}")
    int delete(int videoid);

    /**
     * 修改
     * @param map
     * @return
     */
    @Update("update trainvideo set videoname=#{videoname},intro=#{intro},videopath=#{videopath},sshotpath=#{sshotpath},courseid=#{courseid} " +
            "where videoid=#{videoid}")
    int update(Map map);
}
